# -*- coding: utf-8 -*-
from django.shortcuts import render
from django.views.decorators.csrf import csrf_exempt

from djmarkitup.renderers import DJMIU_MARKUP_RENDERERS


@csrf_exempt
def render_preview(req, markup_language):
    render_func = DJMIU_MARKUP_RENDERERS.get(markup_language, None)
    data = req.POST.get('data', u'')
    if render_func is None:
        res = data
    else:
        res = render_func(data)
    ctx = dict(preview=res)
    return render(req, 'djmarkitup/preview.html', ctx)
